#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import Tkinter

from login import Login
from channel import Channel
from program import Program
import utils


class Application(Tkinter.Frame):
    def __init__(self, master=None):
        Tkinter.Frame.__init__(self, master)

        self.__padx = 5
        self.__pady = 5

        self.columnconfigure(0, weight=5)

        self.grid(
            row=0, column=0, sticky='nswe', padx=self.__padx, pady=self.__pady)

        self.init()

    def init(self):
        self._login = Login()
        self._channel = Channel()
        self._program = Program()

        self._login.login()

        father_id = self._channel.create()
        print('father_id: %s' % father_id)
        self._program.create(father_id)
        self.init_ui()

    def init_ui(self):
        self.father_id_label = Tkinter.Label(self, text=u'频道ID')
        self.father_id_label.grid(row=0, column=0, sticky='w')

        self.father_id_str = Tkinter.StringVar()
        self.father_id = Tkinter.Entry(self, textvariable=self.father_id_str)
        self.father_id.grid(row=0, column=1, columnspan=3)

        self.program_add_btn = Tkinter.Button(
            self, text=u'节目新增', command=self.create_program)
        self.program_add_btn.grid(row=1, column=0, columnspan=4)

    def create_program(self):
        self._program.create(fatherId=self.father_id_str.get())


if __name__ == '__main__':
    root = Tkinter.Tk()
    root.title('EPG - selenium')
    # root.resizable(0, 0)
    root.columnconfigure(0, weight=1)
    app = Application(root)
    root.geometry('320x240')
    root.mainloop()
    utils.destroy_browser()
